cmake_minimum_required(VERSION 3.10)
project(BrainfuckIDE)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Windows 特定设置
if(MSVC)
    # MSVC 编译器设置
    add_compile_options("/W4" "/utf8")
    add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
    add_compile_options("/wd4996")  # 禁用 _CRT_SECURE_NO_WARNINGS 相关警告
    
    # 设置子系统为控制台
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE")
else()
    # MinGW 编译器设置
    add_compile_options("-Wall" "-Wextra")
    add_compile_definitions(_WIN32_WINNT=0x0600)
endif()

# 创建可执行文件
add_executable(brainfuck_ide
    Windows.cpp
)

# Windows API 库链接
target_link_libraries(brainfuck_ide 
    kernel32 
    user32 
    gdi32 
    winspool 
    shell32 
    ole32 
    oleaut32 
    uuid 
    comdlg32 
    advapi32
)

# 设置输出目录
set_target_properties(brainfuck_ide PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
)

# 创建运行目标
add_custom_target(run
    COMMAND brainfuck_ide
    DEPENDS brainfuck_ide
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
    COMMENT "运行 Brainfuck IDE"
)

# 安装目标（可选）
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "..." FORCE)
endif()

install(TARGETS brainfuck_ide
    RUNTIME DESTINATION bin
)

# 构建信息
message(STATUS "构建 Windows Brainfuck IDE")
message(STATUS "编译器: ${CMAKE_CXX_COMPILER}")
message(STATUS "构建类型: ${CMAKE_BUILD_TYPE}")
message(STATUS "输出目录: ${CMAKE_BINARY_DIR}/bin")